# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-minitest-hooks
pkgver=1.5.0
pkgrel=1
pkgdesc='Around and before_all/after_all/around_all hooks for Minitest'
arch=(any)
url='https://github.com/jeremyevans/minitest-hooks'
license=(MIT)
depends=(ruby-minitest)
makedepends=(ruby-sequel ruby-sqlite3 ruby-rake ruby-minitest-global_expectations)
options=(!emptydirs)
source=(https://github.com/jeremyevans/minitest-hooks/archive/$pkgver/$pkgname-$pkgver.tar.gz
        https://github.com/jeremyevans/minitest-hooks/commit/ce134f2dd286c138a16023dc0dd602f8445e19fd.patch
        https://github.com/jeremyevans/minitest-hooks/commit/94bec27e6426f1acc45c7cc950f8b922a5e5521a.patch)
sha256sums=('de9df7752d64422b371605eab6f2c9ac7ed555a8ae9593dce3c325f8a1c4caed'
            '4a3ba8cc11275399d2d620d6a394bf606776b16a400a5b01adc5bfdadcdad454'
            'c503615270b14aea93ac7645f38574066bc3ada86833a47426a5914d92553c99')

prepare() {
  cd minitest-hooks-$pkgver
  patch -p1 -i ../ce134f2dd286c138a16023dc0dd602f8445e19fd.patch
  patch -p1 -i ../94bec27e6426f1acc45c7cc950f8b922a5e5521a.patch
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd minitest-hooks-$pkgver
  gem build minitest-hooks.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    minitest-hooks-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd minitest-hooks-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd minitest-hooks-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 MIT-LICENSE -t "$pkgdir"/usr/share/licenses/$pkgname/
}
